﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZDSoft.LMS.Service;
using ZDSoft.LMS.Core;
using System.Text;
using ZDSoft.LMS.Component;
using ZDSoft.LMS.Domain;
using ZDSoft.LMS.Web.Apps;

namespace ZDSoft.LMS.Web.Controllers
{
    public class AuthorizeController : UcController
    {
        public ActionResult Index(int roleID=0,int topFunctionID = 0)
        {
            if (roleID == 0) roleID = AppHelper.LoginedUser.Roles[0].ID;//如果角色为空，则初始化当前用户的其中一种角色
            Role role = Container.Instance.Resolve<IRoleService>().Get(roleID);
            IList<SystemFunctionDto> functions = null;
            if (topFunctionID == 0)
            {
                functions = Container.Instance.Resolve<ISystemFunctionService>().GetAllByRoleID(roleID);
            }
            else
            {
                functions = Container.Instance.Resolve<ISystemFunctionService>().GetByParentIDAndRoleID(topFunctionID,roleID);
            }
            ViewBag.RoleID = roleID;
            ViewBag.TopFunctions = Container.Instance.Resolve<ISystemFunctionService>().GetTopFunction().OrderBy(o=>o.Idx);
            ViewBag.FunctionList = functions;
            return View(role);
        }
    }
}
